<?php

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

class ZProblemNum {

	public $conn;

	public function __construct() {
		$this->conn = Yii::app()->db;
	}

	/*
	* 分页列表
	*/

	static public function _getAllproblemnum($search,$role_list='',$school_list='',$subject_list='',$exam_id = '') {
		$where = " WHERE 1=1 ";
		$sql = ' SELECT "teacher_id","teacher_name","school_name","exam_id","teacher_num","teacher_pswd" FROM "{{teacher}}" ';
		$sqlcount = ' SELECT count(*) FROM "{{teacher}}" ';
		if (isset($search['exam_id']) && !empty($search['exam_id']) > 0) {
			$where.= ' AND "exam_id" = ' . $search['exam_id'];
                }else{
                    if($role_list != 1 && !empty($exam_id)){
                        $where .= ' AND "exam_id" IN (' . $exam_id . ')';
		}
                }
		if (isset($search['subject_id']) && !empty($search['subject_id']) > 0) {
			$where.= ' AND "subject_id" = ' . $search['subject_id'];
                }else{
                    if($role_list != 1 && !empty($subject_list)){
                        $where .= ' AND "subject_id" IN (' . $subject_list . ')';
		}
                }
		if (isset($search['school_id']) && !empty($search['school_id']) > 0) {
			$where.= ' AND "school_id" = ' . $search['school_id'];
                }else{
                    if($role_list != 1 && !empty($school_list)){
                        $where .= ' AND "school_id" IN (' . $school_list . ')';
		}
                }
		if (isset($search['username']) && !empty($search['username'])) {
			$where.= ' AND "teacher_name" LIKE \'%'.$search['username'].'%\'';
		}
		$data = ZCommon::getDaoPageList($sql . $where, $sqlcount . $where, 8);
		return $data;
	}

	/*
	* 获取教师信息
	* @auther wf
	*/

	 static  function _getTeacherOne($teacher_id) {
		$sql = ' SELECT "teacher_id","teacher_name" FROM "{{teacher}}" WHERE "teacher_id" = ' . $teacher_id;
		$data = Yii::app()->db->createCommand($sql)->queryRow();
		return $data;
	}

	/*
	* 获取教学科目
	*/

	static public function _getAllsubject() {
		$subject = array();
		$examdata = new ExamData();
		$subjectall = $examdata->_getSubject();
		if ($subjectall) {
			foreach ($subjectall as $key => $one) {
				$subject[$one['subject_id']] = $one['subject_name'];
			}
		}
		return $subject;
	}

	/*
	* 获取对应题号
	*/

	static public function _getAllproblem($teacher_id) {
		$sql = ' SELECT "num_id" FROM "{{teacher_num}}" WHERE "teacher_id" LIKE \'%'.$teacher_id.'%\' OR "teacher_id" LIKE \'%'.$teacher_id.'\' OR "teacher_id" LIKE \'%'.$teacher_id.'\' OR "teacher_id" LIKE \''.$teacher_id.'%\'';
		$data = Yii::app()->db->createCommand($sql)->queryAll();
		return $data;
	}

	/*     * ***规则***** */

	static public function _getAllproblemrule($search) {
		$sql = ' SELECT * FROM "{{problemrule}}" ';
		$sqlcount = ' SELECT count(*) FROM "{{problemrule}}" ';
		$where = ' WHERE "id" > 0  ';
		if (Func::check_search($search['code']) ) {
			$where.= ' AND "code" LIKE \'%' . $search['code'] . '%\'';
		}
		if (Func::check_search($search['name']) > 0) {
			$where.= ' AND "name" = \'%' . $search['name'] . '%\'';
		}
		if (isset($search['is_show']) && !empty($search['is_show']) > 0) {
			$where.= ' AND "is_show" = ' . $search['is_show'];
		}
		$order = ' ORDER BY "code" ASC ';
		$data = ZCommon::getDaoPageList($sql . $where . $order, $sqlcount . $where . $order, 8);
		return $data;
	}

	/*
	* 规则详情映射
	*/

	static public function _getAllproblemruledetail($search) {
		$sql = ' SELECT * FROM "{{problemrule_detail}}" ';
		$sqlcount = ' SELECT count(*) FROM "{{problemrule_detail}}" ';
		$where = ' WHERE "id" > 0  ';
		if (isset($search['problemrule_id']) && !empty($search['problemrule_id']) > 0) {
			$where.= ' AND "problemrule_id" = ' . $search['problemrule_id'];
		}
		$order = ' ORDER BY TO_NUMBER("number") ASC ';
		$data = ZCommon::getDaoPageList($sql . $where . $order, $sqlcount . $where . $order, 8);
		return $data;
	}
	/*
	* 全通规则详情
	*/
	static public function _getAllproblemrule_detail($where='') {
		$sql = ' SELECT * FROM "{{problemrule_detail}}" '.$where;
		$data = Yii::app()->db->createCommand($sql)->queryAll();
		return $data;
	}

	/*
	* 取单个科目对应的所有教师
	*/

	static public function _getAllproblemteacher($exam_id,$subject_id,$where = false) {
		$sql = ' SELECT "teacher_name","teacher_id","leader" FROM "{{teacher}}" WHERE "subject_id" = ' . $subject_id.' AND "exam_id" = '.$exam_id;
                if($where){
                    $sql.= $where;
                }
		$data = Yii::app()->db->createCommand($sql)->queryAll();
		return $data;
	}

}

?>
